﻿using Padsurface.CoreAudio.Components.WASAPI;
using Padsurface.CoreAudio.Components.WASAPI.Interfaces;
using Padsurface.CoreAudio.Wrappers.Services.Interfaces;
using System;
using System.Composition;
using System.Runtime.InteropServices;

namespace Padsurface.CoreAudio.Wrappers.Services
{
    [Export(typeof(IAudioCaptureClientActivator))]
    internal class AudioCaptureClientActivator : IAudioCaptureClientActivator
    {
        public IAudioCaptureClient Activate(IAudioClient audioClient)
        {
            if (audioClient == null) throw new ArgumentNullException("audioClient");

            object audioCaptureClientInterface;
            Marshal.ThrowExceptionForHR(
                audioClient.GetService(new Guid(ComIIDs.IAudioCaptureClientIID), out audioCaptureClientInterface));

            return audioCaptureClientInterface as IAudioCaptureClient;
        }
    }
}